package com.inspire.myapp;

import java.util.Hashtable;

import com.codename1.ui.Component;
import com.codename1.ui.Container;
import com.codename1.ui.Display;
import com.codename1.ui.Image;
import com.codename1.ui.plaf.Border;
import com.codename1.ui.plaf.Style;

public class utils {

	static public Image reformeImage(Image img, int ir,int il,int it,int ib,int finalWidth,int finalHeight) {
		int ih=img.getHeight();
		int iw=img.getWidth();

		Hashtable imgs = new Hashtable();
		imgs.put("lt",img.subImage(0, 0, il, it,true));
		imgs.put("lc",img.subImage(0, it, il, ih-it-ib,true));
		imgs.put("lb",img.subImage(0, ih-ib, il, ib,true));

		imgs.put("rt",img.subImage(iw-ir, 0, ir, it,true));
		imgs.put("rc",img.subImage(iw-ir, it, ir, ih-it-ib,true));
		imgs.put("rb",img.subImage(iw-ir, ih-ib, ir, ib,true));
		
		imgs.put("tc",img.subImage(il, 0, iw-il-ir, it,true));
		imgs.put("bc",img.subImage(il, ih-ib, iw-il-ir, ib,true));
		
		imgs.put("cc",img.subImage(il, it, iw-il-ir, ih-it-ib,true));
		
		int fw=finalWidth;
		int fh=finalHeight;
		Image i = Image.createImage(fw, fh);
		i.getGraphics().drawImage((Image) imgs.get("cc"), il, it, fw-il-ir, fh-it-ib);
		i.getGraphics().drawImage((Image) imgs.get("lc"), 0, it, il, fh-it-ib);
		i.getGraphics().drawImage((Image) imgs.get("rc"), fw-ir, it, ir, fh-it-ib);
		i.getGraphics().drawImage((Image) imgs.get("tc"), il, 0, fw-il-ir, it);
		i.getGraphics().drawImage((Image) imgs.get("bc"), il, fh-ib, fw-il-ir, ib);
		
		i.getGraphics().drawImage((Image) imgs.get("lt"), 0, 0, il, it);
		i.getGraphics().drawImage((Image) imgs.get("lb"), 0, fh-ib, il, ib);
		i.getGraphics().drawImage((Image) imgs.get("rt"), fw-ir, 0, ir, it);
		i.getGraphics().drawImage((Image) imgs.get("rb"), fw-ir, fh-ib, ir, ib);
		
		
		

		return i;
	}
	
	static public Image rogneImage(Image img, int ir,int il,int it,int ib) {
		int ih=img.getHeight();
		int iw=img.getWidth();

		Hashtable imgs = new Hashtable();
		
		imgs.put("cc",img.subImage(il, it, iw-il-ir, ih-it-ib,true));

		Image i = Image.createImage(iw, ih);
		i.getGraphics().drawImage((Image) imgs.get("cc"), 0, 0, iw, ih);
		return i;
	}
	
	static public void setBackground(Style style,Image imgback){
		style.setBgImage(imgback, true);
		style.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED);
		style.setBorder(Border.getEmpty());
		style.setAlignment(Component.RIGHT);
	}
	
	
}
